package com.yuexun.dhdoctor.module.Contract.adapter;

import android.view.View;
import android.widget.AbsListView;
import android.widget.CheckBox;

import com.yuexun.dhdoctor.R;
import com.yuexun.dhdoctor.module.Contract.bean.People;

import org.kymjs.kjframe.widget.AdapterHolder;
import org.kymjs.kjframe.widget.KJAdapter;

import java.util.ArrayList;
import java.util.Collection;

/**
 * Created by work-jx on 2016/7/25.
 */
public class DeleteMemberAdapter extends KJAdapter<People> {
    ArrayList<People> datasEntities_change = new ArrayList<People>();

    public DeleteMemberAdapter(AbsListView view, Collection<People> mDatas, int itemLayoutId) {
        super(view, mDatas, itemLayoutId);
    }

    @Override
    public void convert(AdapterHolder adapterHolder, People people, boolean b, final int position) {
        CheckBox add_checkbox= adapterHolder.getView(R.id.add_checkbox);
        adapterHolder.setText(R.id.tvName, people.getUserName());
        if(datasEntities_change.contains(people))
        {
            add_checkbox.setChecked(true);
        }
        else {
            add_checkbox.setChecked(false);
        }
        onPicClick(add_checkbox, add_checkbox, this.getItem(position));
    }

    private void onPicClick(View view, final CheckBox checkBox, final People datasEntity) {
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (datasEntities_change.contains(datasEntity)) {
                    datasEntities_change.remove(datasEntity);
                    checkBox.setChecked(false);
                } else {
                    datasEntities_change.add(datasEntity);
                    checkBox.setChecked(true);
                }
            }
        });
    }

    public ArrayList<People> getArrayList() {
        return datasEntities_change;
    }
}
